@include('admin.header')
<style type="text/css">
.pic-list li {
	margin-bottom: 5px;
}
</style>
</head>
<body>
	<div class="wrap js-check-wrap">
		
		<form method="post" class="form-horizontal js-category-add">
			<div class="row-fluid">
				<table class="table table-bordered">
					<tr>
						<th>店铺名称</th>
						<td>
							<input type="text" style="width:400px;" name="merchant_name"  value="{{$data->merchant_name or '' }}" placeholder="请输入店铺名称"/>
						</td>
					</tr>				
					<tr>
						<th>简称</th>
						<td>
							<input type="text" style="width:400px;" name="short_name"  value="{{$data->short_name or '' }}" placeholder="请输入简称"/>
						</td>
					</tr>					
					<tr>
						<th>店铺地址</th>
						<td>
							<input type="text" style="width:400px;" name="merchant_address"  value="{{$data->merchant_address or '' }}" placeholder="请输入店铺地址"/>
						</td>
					</tr>	
					<tr>
						<th>服务电话</th>
						<td>
							<input type="text" style="width:400px;" name="service_phone"  value="{{$data->service_phone or '' }}" placeholder="请输入服务电话"/>
						</td>
					</tr>
					<tr>
						<th>营业时间</th>
						<td>
							<input type="text" style="width:400px;" name="open_time"  value="{{$data->open_time or '' }}" placeholder="请输入营业时间"/>
						</td>
					</tr>									
					<tr>
						<th>logo预览图</th>
						<td>
							<img id='thumb' src="{{$data->logo or '/static/admin/assets/images/default-thumbnail.png'}}" style="height:120px;" />
							<input type="file" name="image" onchange="upload(this)" />
							<input type="hidden" name="logo" value="{{$data->logo or ''}}" />
						</td>
					</tr>										
				</table>
			</div>
			<div class="form-actions">
				<input type="hidden" name="_token"  value="{{csrf_token()}}"/>
				<button class="btn btn-primary js-ajax-submit" type="submit">提交</button>
				<a class="btn" href="{{asset('admin/adminList')}}">返回</a>
			</div>
		</form>
	</div>
	<script type="text/javascript" src="/static/js/common.js"></script>
	<script type="text/javascript" src="/static/js/validate/validate.js"></script>
	<script type="text/javascript" src="/static/js/layer/layer.js"></script>
	<script type="text/javascript" src="/static/js/ajaxfileupload.js"></script>
	<script type="text/javascript">
		$(function() {
			$(".js-category-add").validate({
				rules: {
					merchant_name: {
						required: true
					},
					short_name: {
						required: true
					},
					merchant_address: {
						required: true
					},
					service_phone: {
						required: true
					},
					open_time: {
						required: true
					}
					,
					logo: {
						required: true
					}
				},
				messages: {
					merchant_name: {
						required: "请输入店铺名称"
					},
					short_name: {
						required: "请输入简称"
					},
					merchant_address: {
						required: "请输入店铺地址"
					},
					service_phone: {
						required: "请输入服务电话"
					},
					open_time: {
						required: "请输入营业时间"
					},
					logo: {
						required: "请上传图片"
					},
				},
				submitHandler: function () {
					$.post("/merchant/edit",$('.js-category-add').serialize(), function (msg) {
						if (msg.status == 1) {
							layer.confirm(msg.info, {
								btn: ['确定']
							}, function(){
								window.location.reload();
							});
						} else {
							showMsg(msg.info);
						}
					}, 'json');
					return false;
				}
			});
		});
		/**
		 * layer提示
		 */
		function showMsg(msg){
			layer.alert(msg, {
				title: '提示',
				icon: 2,
			});
		}

		function upload(t){
			var file = t.files[0],name = $(t).attr('name');
			if(file){
				if($(t).siblings('.tips').length <= 0){
					$(t).after('<span class="tips"></span>');
				}
				var tips = $(t).siblings('.tips'),hidden = $(t).siblings('[type=hidden]');
				tips.text('上传中...');
				var fr = new FileReader();
				fr.onloadend = function(e) {
					post('/index/upload_image',{image:e.target.result},function(data){
						hidden.val(data);
						tips.text('上传完成');
						$('#thumb').attr('src',data); //设置img图片
					},function(info){
						tips.text('失败，'+info);
					});
				};
				fr.readAsDataURL(file);
			}else{
			}
		};		

	</script>
</body>
</html>